package com.huawei;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Z-hong on 2024/7/4.
 */

public class HJ20 {
    public static final String Legitimate = "OK";
    public static final String Illegality = "NG";

    public static class Node{
        public int i;
        public Node next;
    }

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            System.out.println(checkInput(scanner.next()));
        }
    }

    public static String checkInput(String input) {

        if (input.length() < 8) {
            return Illegality;
        }
        int count = 0;
        //正则判断是否存在数字
        if (input.matches(".*\\d+.*")) {
            count++;
        }
        //正则判断是否存在大写字母
        if (input.matches(".*[A-Z]+.*")) {
            count++;
        }
        //正则判断是否存在小写字母
        if (input.matches(".*[a-z]+.*")) {
            count++;
        }
        //正则判断是否存在特殊符号
        if (input.matches(".*[~!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>/?]+.*")) {
            count++;
        }
        if (count < 3){
            return Illegality;
        }
        //判断是否存在长度大于2的子串重复

        Node[] nodes=new Node[127];
        char[] chars=input.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(nodes[chars[i]]==null){
                nodes[chars[i]]=new Node();
                nodes[chars[i]].i=i;
                nodes[chars[i]].next=null;
            }else{
                Node node=nodes[chars[i]];
                while (node.next!=null){
                    node=node.next;
                }
                node.next=new Node();
                node.next.i=i;
                node.next.next=null;
            }
        }
        for (int i = 0; i < nodes.length; i++) {
            Node node=nodes[i];
            while(node!=null){
                Node next=node.next;
                while (next!=null){
                   Boolean flag=check(node.i,next.i,chars);
                   if (!flag){
                       return Illegality;
                   }
                   next=next.next;
                }
                node=node.next;
            }
        }

        return Legitimate;

    }

    public static boolean check(int i,int j,char[] arr){
        int count = 0;
        while(i< arr.length&&j<arr.length){
            if(count>2) return false;

            if(arr[i]==arr[j]){
                count++;
                i++;j++;
            }else{
                return true;
            }
        }
        return true;
    }

}
